<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">系统管理</a>
        <a>
          <cite>系统用户管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:refresh();" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row" style="display: none">
        <form class="layui-form layui-col-md12 x-so">
            <input class="layui-input" placeholder="开始日" name="start" id="start">
            <input class="layui-input" placeholder="截止日" name="end" id="end">
            <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
    *{<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>}*
        <button class="layui-btn" onclick="openIframe('添加用户','/admin/user/detail?r=' + Math.random())">
            <i class="layui-icon"></i>添加
        </button>
    *{<span class="x-right" style="line-height:40px">共有数据：88 条</span>}*
    </xblock>
    <table class="layui-table" id="userlist" lay-filter="opera">
    </table>
</div>
<script type="text/html" id="btn_list">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    function reloadTable() {
        layui.table.reload('userlist');
    }

    layui.use('table', function () {
        let table = layui.table;
        table.render({
            elem: '#userlist',
            url: '/admin/user/list',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
                first: true, //不显示首页
                last: true //不显示尾页

            },
            cols: [[
                {field: 'id', width: '10%', title: 'ID', sort: true},
                {field: 'username', width: '25%', title: '账号'},
                {field: 'realname', width: '25%', title: '用户名', sort: true},
                {
                    field: 'enabled', width: '15%', title: '状态', templet: function (d) {
                    return d.enabled === 1 ? '启用' : '禁用';
                }
                },
                {field: 'tool', width: '25%', title: '操作', templet: '#btn_list', unresize: true}
            ]],
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'rows' //每页数据量的参数名，默认：limit
            }
        });

        //监听工具条
        table.on('tool(opera)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.post("/admin/user/delet", {'user.id': data['id']}, function (json) {
                        if (json.code === 0) {
                            reloadTable();
                            layer.msg('删除成功');
                        }
                    });
                });
            } else if (obj.event === 'edit') {
//                    layer.alert('编辑行：<br>'+ JSON.stringify(data))
                openIframe("编辑", "/admin/user/detail?id=" + data['id'] + "&r=" + Math.random())
            } else {
                console.log(obj.data);
                console.log(obj.event);
            }
        });
        $('.operaTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>

</html>